#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   level_rate_config.py    
@Contact :   pengwei.sun@aihuishou.com
@License :   (C)Copyright aihuishou

@Modify Time      @Author       @Version    @Desciption
------------      -----------   --------    -----------
2021-01-10 16:48   pengwei.sun      1.0         None
'''

import datetime
import pandas as pd
import numpy as np
from src.utils.config import logger
from src.utils.db_processor import mysql_prediction_processor
from src.utils.db_processor import mysql_prediction_processor
from src.utils.util import get_today, check_date_str, format_date_string
from src.tablet.levelrate.config_utils import level_rank_df,product_level_df,apple_product_ids
import time

"""
取数逻辑 ：
按天汇总skuleve的价格：取平均数
 --b:筛选出具有S,A,B等级，并且等级数存在数大于1的sku
"""
SETTLE_DATA = """
select a.secondary_level_template_id as property_level_template_id,CONCAT(a.secondary_level_template_id,'_',a.product_brand_id) as property_template_brand,a.mapping_product_sku_id as product_sku_id,CONCAT(a.secondary_level_template_id,'_',a.product_brand_id,'_',a.mapping_product_sku_id) as product_sku,
a.mapping_product_level_id as product_level_id,a.mapping_product_level_name as product_level_name,substring(a.mapping_product_level_name,1,1) as level_sub,
avg(a.real_sell_price) as price,
COUNT(*) AS sale_num,
count(distinct a.shop_out_date) as cnt_date
 from product_price_info  a
inner join (
	select secondary_level_template_id,product_id,mapping_product_sku_id,
	count(distinct mapping_product_level_id) AS cnt,
	count(distinct product_level_id_2) AS cnt1
	from
	(
	select distinct secondary_level_template_id,product_id,mapping_product_sku_id ,mapping_product_level_name ,
	mapping_product_level_id,
	case when substring(mapping_product_level_name,1,1) in ('S','A','B') 
	THEN mapping_product_level_id ELSE null end product_level_id_2 
	 from product_price_info a
	where shop_out_date between DATE_FORMAT(date_sub(curdate(),interval 7 day),'%Y%m%d')  and  DATE_FORMAT(date_sub(curdate(),interval 0 day),'%Y%m%d') and product_category_id=6
	and  product_source_id in (101,103)
    and mapping_product_level_name is not null
    and secondary_level_template_id>0
    and (a.sale_out_cnt is  null OR a.sale_out_cnt<=1)
	) a
	GROUP BY 1,2
	having  count(distinct product_level_id_2)>0 and count(distinct mapping_product_level_id)>=2
)b
on  a.product_id=b.product_id and a.mapping_product_sku_id=b.mapping_product_sku_id

where a.shop_out_date between DATE_FORMAT(date_sub(curdate(),interval 7 day),'%Y%m%d')  and  DATE_FORMAT(date_sub(curdate(),interval 0 day),'%Y%m%d') and a.product_category_id=6  and mapping_product_level_id>0
and  a.product_source_id in (101,103)
and (a.sale_out_cnt is  null OR a.sale_out_cnt<=1)
and a.mapping_product_level_name is not null
and a.secondary_level_template_id>0
GROUP BY 1,2,3,4,5,6
order by 1,2,3,4
"""

SETTLE_DATA_2 = """
select a.secondary_level_template_id as property_level_template_id,CONCAT(a.secondary_level_template_id,'_',a.product_brand_id) as property_template_brand,a.mapping_product_sku_id as product_sku_id,CONCAT(a.secondary_level_template_id,'_',a.product_brand_id,'_',a.mapping_product_sku_id) as product_sku,
a.mapping_product_level_id as product_level_id,a.mapping_product_level_name as product_level_name,substring(a.mapping_product_level_name,1,1) as level_sub,
avg(a.real_sell_price) as price,
COUNT(*) AS sale_num,
count(distinct a.shop_out_date) as cnt_date
 from product_price_info  a
inner join (
	select secondary_level_template_id,product_id,mapping_product_sku_id,
	count(distinct mapping_product_level_id) AS cnt,
	count(distinct product_level_id_2) AS cnt1
	from
	(
	select distinct secondary_level_template_id,product_id,mapping_product_sku_id ,mapping_product_level_name ,
	mapping_product_level_id,
	case when substring(mapping_product_level_name,1,1) in ('S','A','B') 
	THEN mapping_product_level_id ELSE null end product_level_id_2 
	 from product_price_info a
	where  shop_out_date between DATE_FORMAT(date_sub(curdate(),interval 14 day),'%Y%m%d')  and DATE_FORMAT(date_sub(curdate(),interval 8 day),'%Y%m%d')  
	and product_category_id=6  and mapping_product_level_id>0
	and  product_source_id in (101,103)
	and (a.sale_out_cnt is  null OR a.sale_out_cnt<=1)
    and mapping_product_level_name is not null
    and secondary_level_template_id>0
	) a
	GROUP BY 1,2
	having  count(distinct product_level_id_2)>0 and count(distinct mapping_product_level_id)>=2
)b
on  a.product_id=b.product_id and a.mapping_product_sku_id=b.mapping_product_sku_id

where a.shop_out_date between DATE_FORMAT(date_sub(curdate(),interval 14 day),'%Y%m%d')  and DATE_FORMAT(date_sub(curdate(),interval 8 day),'%Y%m%d')  
 and a.product_category_id=6
and  a.product_source_id in (101,103)
and (a.sale_out_cnt is  null OR a.sale_out_cnt<=1)
and a.mapping_product_level_name is not null
and a.secondary_level_template_id>0
GROUP BY 1,2,3,4,5,6
order by 1,2,3,4
"""

SETTLE_DATA_3 = """
select a.secondary_level_template_id as property_level_template_id,CONCAT(a.secondary_level_template_id,'_',a.product_brand_id) as property_template_brand,a.mapping_product_sku_id as product_sku_id,CONCAT(a.secondary_level_template_id,'_',a.product_brand_id,'_',a.mapping_product_sku_id) as product_sku,
a.mapping_product_level_id as product_level_id,a.mapping_product_level_name as product_level_name,substring(a.mapping_product_level_name,1,1) as level_sub,
avg(a.real_sell_price) as price,
COUNT(*) AS sale_num,
count(distinct a.shop_out_date) as cnt_date
 from product_price_info  a
inner join (
	select secondary_level_template_id,product_id,mapping_product_sku_id,
	count(distinct mapping_product_level_id) AS cnt,
	count(distinct product_level_id_2) AS cnt1
	from
	(
	select distinct secondary_level_template_id,product_id,mapping_product_sku_id ,mapping_product_level_name ,
	mapping_product_level_id,
	case when substring(mapping_product_level_name,1,1) in ('S','A','B') 
	THEN mapping_product_level_id ELSE null end product_level_id_2 
	 from product_price_info a
	where shop_out_date between DATE_FORMAT(date_sub(curdate(),interval 21 day),'%Y%m%d')  and DATE_FORMAT(date_sub(curdate(),interval 15 day),'%Y%m%d')
	  and product_category_id=6  and mapping_product_level_id>0
	and  product_source_id in (101,103)
	and (a.sale_out_cnt is  null OR a.sale_out_cnt<=1)
    and mapping_product_level_name is not null
    and secondary_level_template_id>0
	) a
	GROUP BY 1,2
	having  count(distinct product_level_id_2)>0 and count(distinct mapping_product_level_id)>=2
)b
on  a.product_id=b.product_id and a.mapping_product_sku_id=b.mapping_product_sku_id

where  a.shop_out_date between DATE_FORMAT(date_sub(curdate(),interval 21 day),'%Y%m%d')  and DATE_FORMAT(date_sub(curdate(),interval 15 day),'%Y%m%d') 
 and a.product_category_id=6 
and  a.product_source_id in (101,103)
and (a.sale_out_cnt is  null OR a.sale_out_cnt<=1)
and a.mapping_product_level_name is not null
and a.secondary_level_template_id>0
GROUP BY 1,2,3,4,5,6
order by 1,2,3,4
"""

#--and a.product_id=32291 S,A,B基准价格
BASE_PRICE_DATA = """
SELECT level_name,price as base_price FROM c_level_base_price
"""


class TemplateLevelRate:
    def __init__(self,sql):

        # sql = SETTLE_DATA
        #获取型号对应的skulevel聚合后的数据
        if sql is None:
            self.query_sql=SETTLE_DATA
        else:
            self.query_sql=sql

        self.data = mysql_prediction_processor.load_sql(self.query_sql)
        self.data = self.data.loc[self.data.product_level_id > 0]
        #基础等级价格
        self.base_price_df = mysql_prediction_processor.load_sql(BASE_PRICE_DATA)
        self.level_rank_df=level_rank_df

        self.product_level_df =product_level_df

    def fun1(self):
        #根据售卖数量和等级计算每个等级得分，以便后续sku 筛选:高等级的等级id较小，所以采取1000-等级id，使得，相同数量的情况下，高等级的优先选择
        self.data['score']=1000-self.data.product_level_id+self.data.sale_num*1000
        #首先筛选出sku中 有S,A,B等级数据
        data_sku_base_level_df=self.data.loc[self.data.level_sub.isin(['S','A','B'])]

        # a= data_sku_base_level_df.groupby(by=['product_id','product_sku_id'], as_index=False)['score'].max()
        # index= data_sku_base_level_df.groupby(by=['product_id','product_sku_id'])['score'].idxmax()

        #找出数据中score得分最高的level
        base_level=data_sku_base_level_df.loc[data_sku_base_level_df.sort_values(['product_sku','score']).drop_duplicates('product_sku',keep='last').index]

        base_level.rename(columns={'price':'price_base','score':'score_base','sale_num':'base_sale_num'},inplace=True)

        # base_level
        #统计出满足条件的型号下 sku的数量
        base_product_sku_size=data_sku_base_level_df[['property_template_brand','product_sku_id']].groupby('property_template_brand').agg({'product_sku_id': pd.Series.nunique}).reset_index()
        base_product_sku_size.rename(columns={'product_sku_id':'product_sku_num'},inplace=True)


        #给筛选出的基础数据拼接上其对应的基础价格
        base_level=base_level.merge(self.base_price_df,left_on=['product_level_name'],right_on=['level_name'])
        base_base_level_sale_num=base_level.groupby(by=['property_template_brand'])['base_sale_num'].agg({'base_level_sale_sum':'sum'})
        base_level=base_level.merge(base_base_level_sale_num,on='property_template_brand')
        base_level['sku_weight']=base_level.base_sale_num/base_level.base_level_sale_sum

        # 给数据拼接上他们各自的基础信息
        df_all = self.data.merge(base_level[['product_sku', 'price_base', 'score_base', 'base_price']], on=['product_sku'])

        base_product_sale_num=df_all.groupby('property_template_brand')['sale_num'].agg({'product_sale_sum':'sum' }).reset_index()
        base_product_info=base_product_sku_size.merge(base_product_sale_num,left_on=['property_template_brand'],right_on=['property_template_brand'])
        return base_level,base_product_info

    def fun2(self,base_level,base_product_info):
        t1 = time.time()
        # 给数据拼接上他们各自的基础信息
        df_all = self.data.merge(base_level[['product_sku', 'price_base', 'score_base', 'base_price','sku_weight','base_level_sale_sum','base_sale_num']],
                                 on=['product_sku'])

        #计算等级比率，并还原成基础价格
        df_all['level_rate']=df_all.price/df_all.price_base
        df_all['to_base_price']=df_all.base_price*df_all.level_rate
        df_all = df_all.loc[df_all.product_level_id > 0]
        df_all['product_level_id'] = df_all['product_level_id'].astype(int)
        #型号维度的汇总
        df_all['product_level_id_name']=df_all['property_template_brand'].astype(str)+'_'+df_all['product_level_id'].astype(str)+'_'+df_all['product_level_name']

        #求出汇总后的数据的，平均价格，平均售卖数量等信息
        result1=df_all.groupby(by='product_level_id_name')['to_base_price'].agg({'price_mean':'mean','price_max':'max','price_min':'min','price_media':'median'}).reset_index()#这里
        #型号下 各个等级的 售卖数量相关信息
        cnt_res=df_all.groupby(by='product_level_id_name')['sale_num'].agg({'sale_sum':'sum','sku_cnt':'count'}).reset_index()#这里

        df_all=df_all.merge(cnt_res,on='product_level_id_name')

        #等级价格汇总时 ，是以此等级售卖出的数量占此等级的比例为权重，进行加权计算
        df_all['level_weight']=df_all['sale_num']/df_all['sale_sum']
        df_all['sku_base_level_weight']=df_all['base_sale_num']/df_all['base_level_sale_sum']
        df_all['zh_level_weight']=df_all['sku_base_level_weight']*df_all['level_weight']
        # df_all['zh_level_weight'](by='product_level_id_name').agg({'price_mean':'sum'})

        weight_res = df_all.groupby(by='product_level_id_name')['zh_level_weight'].agg(
            {'weight_sum': 'sum'}).reset_index()  # 这里


        df_all=df_all.merge(weight_res[['product_level_id_name','weight_sum']],on=['product_level_id_name'])
        df_all['weight']=df_all['zh_level_weight']/df_all.weight_sum

        df_all['to_base_price_weight']=df_all['weight']*df_all['to_base_price']
        result=df_all.groupby(by='product_level_id_name')['to_base_price_weight'].agg({'price_mean':'sum','price_max':'sum','price_min':'sum','price_media':'sum'}).reset_index()#这里

        # resulttmp=result.merge(result1,on='product_level_id_name')

        # result=result.sort_values('price_media',ascending=False).reset_index()
        result['property_template_id']=result['product_level_id_name'].str.split('_',expand=True)[0].astype(np.int64)
        result['level_id']=result['product_level_id_name'].str.split('_',expand=True)[2].astype(np.int64)
        result['brand_id']=result['product_level_id_name'].str.split('_',expand=True)[1].astype(np.int64)
        result['property_template_brand'] = result['property_template_id'].astype(str) + '_' + result[
            'brand_id'].astype(str)

        result=result.merge(base_product_info,how='inner',left_on=['property_template_brand'],right_on=['property_template_brand'])
        result=result.merge(self.level_rank_df,left_on=['level_id'],right_on=['product_level_id'])
        result.loc[result['brand_id'].isin([52]), 'product_level_order_rank'] = result.loc[
            result['brand_id'].isin([52]), 'product_level_order_rank_52']
        result_t=result.merge(cnt_res,on='product_level_id_name')

        #求出汇总后的等级比率和sku占比
        result_t['rate']=result_t.price_media/10000

        result_t['sku_rate']=result_t.sku_cnt/result_t.product_sku_num



        result_t=result_t.sort_values(by=['product_level_order_rank','product_level_id'],ascending=[True,True])
        result_t['rate_f']=result_t['rate']
        result_t=result_t.reset_index()
        # result_t_tmp=result_t
        # size=result_t.shape[0]
        resDf = pd.DataFrame(columns=result_t.columns.tolist())
        grouped = result_t.groupby('property_template_brand')
        del result_t
        for name, group in grouped:

            group=group.sort_values(by=['product_level_order_rank','product_level_id'],ascending=[True,True])
            group.reset_index(drop=True, inplace=True)
            size = group.shape[0]
            result_t = group
            logger.info('property_template_brand:{}'.format(group.loc[0,'property_template_brand']))
            # if group.loc[0,'property_template_brand']=='36_24':
            #     print('dsds')

            for index in range(size):

                if index==0 :
                    if result_t.loc[index, 'sku_rate']>0.3:
                        continue
                    for next in range(1,size,1):
                        if next>=size:
                            continue
                        if result_t.loc[next, 'sku_rate']>0.3:
                            break

                    if (next<size) and ((result_t.loc[index, 'rate_f']-result_t.loc[next, 'rate_f'])/(next-index)>0.10):
                        # for i in range(next-1,index,-1):
                        result_t.loc[index, 'rate_f']=result_t.loc[next, 'rate_f']+0.1*(next-index)



                    # if result_t.loc[index,'rate_f']>1.2:
                        # result_t.loc[index, 'rate_f']=1.2
                    continue

                # if index==size-1:
                #     break
                if (result_t.loc[index,'product_level_id_name'].find('S')>0 \
                    or result_t.loc[index,'product_level_id_name'].find('A')>0 \
                    or result_t.loc[index, 'product_level_id_name'].find('B') > 0):

                    if result_t.loc[index, 'rate_f']-result_t.loc[index-1,'rate_f']>=0 and result_t.loc[index, 'sku_rate']<0.3:
                        result_t.loc[index, 'rate_f'] = result_t.loc[index-1, 'rate_f']-0.01
                    if result_t.loc[index, 'rate_f']-result_t.loc[index-1,'rate_f']>=0 and result_t.loc[index, 'sku_rate']>=0.3 :
                        rate_flag=result_t.loc[index - 1, 'rate_f']
                        flag_index=index - 1
                        x = index - 1
                        for x in range(index-1, 0, -1):
                            if result_t.loc[x, 'sku_rate']>=0.3:
                                rate_flag=result_t.loc[x, 'rate_f']
                                flag_index=x
                                break
                        if index-x>1 and rate_flag-result_t.loc[index, 'rate_f']>0:
                            rate_bulk=(rate_flag - result_t.loc[index, 'rate_f'])/(index-x)
                            for bulk in range(flag_index+1,index-1,1):
                                result_t.loc[bulk, 'rate_f'] = result_t.loc[bulk + 1, 'rate_f'] - rate_bulk
                    continue
                if (result_t.loc[index,'product_level_id_name'].find('C')>0 \
                        or result_t.loc[index, 'product_level_id_name'].find('D') > 0 \
                        or result_t.loc[index, 'product_level_id_name'].find('E') > 0 \
                        or result_t.loc[index, 'product_level_id_name'].find('F') > 0 \
                        or result_t.loc[index, 'product_level_id_name'].find('G') > 0 \
                        or result_t.loc[index, 'product_level_id_name'].find('H') > 0 \
                        or result_t.loc[index, 'product_level_id_name'].find('I') > 0 \
                        or result_t.loc[index, 'product_level_id_name'].find('J') > 0
                        or result_t.loc[index, 'product_level_id_name'].find('K') > 0):

                    if result_t.loc[index, 'rate_f']-result_t.loc[index-1,'rate_f']>=0 and result_t.loc[index, 'sku_rate']<0.2:
                        result_t.loc[index, 'rate_f'] = result_t.loc[index-1, 'rate_f']-0.005
                    if result_t.loc[index, 'rate_f']-result_t.loc[index-1,'rate_f']>=0 and result_t.loc[index, 'sku_rate']>=0.2 :
                        rate_flag=result_t.loc[index - 1, 'rate_f']
                        flag_index=index - 1
                        x=index-1
                        for x in range(index-1, 0, -1):
                            if result_t.loc[x, 'sku_rate']>=0.2:
                                rate_flag=result_t.loc[x, 'rate_f']
                                flag_index=x
                                break
                        if index-x>1 and rate_flag-result_t.loc[index, 'rate_f']>0:
                            rate_bulk=(rate_flag - result_t.loc[index, 'rate_f'])/(index-x)
                            for bulk in range(flag_index+1,index-1,1):
                                result_t.loc[bulk, 'rate_f'] = result_t.loc[bulk + 1, 'rate_f'] - rate_bulk
                    continue
            resDf = resDf.append(result_t.copy())

        resDf['level_id']=resDf.level_id.astype(np.int64)
        product_level_df=self.product_level_df.merge(resDf,how='left',left_on=['template_brand','level_id'],right_on=['property_template_brand','level_id'])
        product_level_df.drop(['product_level_order_rank', 'product_level_order_rank_52'], axis=1, inplace=True)
        product_level_df=product_level_df.merge(self.level_rank_df,left_on=['level_id'],right_on=['product_level_id'])
        product_level_df.loc[product_level_df['product_brand_id'].isin([52]), 'product_level_order_rank'] = product_level_df.loc[
            product_level_df['product_brand_id'].isin([52]), 'product_level_order_rank_52']
        product_level_df=product_level_df.sort_values(['level_template_id','product_level_order_rank'],ascending=True)

        logger.info('template_level_2_rate_v1 process fun2 Data use time @{}'.format(time.time() - t1))
        return product_level_df

def fun3(process_df,rate_f='mean_rate',w='w_mean'):
    t1 = time.time()

    process_df=process_df.reset_index()
    process_df[rate_f]=process_df[rate_f].fillna(-1)
    resDf = pd.DataFrame(columns=process_df.columns.tolist())

    grouped = process_df.groupby('template_brand')
    for name, group in grouped:
        size=group.shape[0]
        group.reset_index(drop=True, inplace=True)
        logger.info('fun3 property_template_brand:{}'.format(group.loc[0, 'template_brand']))
        if size==1:
            resDf = resDf.append(group.copy())
            continue

        for i in range(size):
            if group.loc[i,rate_f]==-1:
                if i==0:
                    next = 0
                    for next in range(i+1,size,1):
                        if group.loc[next, rate_f]>0:
                            break
                    if next==(size-1) and group.loc[next, rate_f]==-1 and i==0:
                        group.loc[i, rate_f]=1
                    else:
                        group.loc[i, rate_f]=group.loc[next, rate_f]+next*0.03
                    continue
                if i>0:
                    next=size
                    for next in range(i+1,size,1):
                        if group.loc[next, rate_f]>0 and group.loc[next, w]>=0.5:
                            break
                    if next<size-1:
                        group.loc[i, rate_f]=group.loc[i-1, rate_f]-(group.loc[i-1, rate_f]-group.loc[next, rate_f])/(next-i+1)

                    else:
                        varience=(group.loc[i - 1, rate_f]-0.1)/(next-i+1)
                        group.loc[i, rate_f] = group.loc[i - 1, rate_f]-varience
                    continue
            else:
                continue
        resDf = resDf.append(group.copy())
    logger.info('template_level_2_rate_v1 process fun3 Data use time @{}'.format(time.time() - t1))
    return resDf





def process_product_level_rate(sql):

    model=TemplateLevelRate(sql)
    base_level,base_product_info=model.fun1()
    product_level_df=model.fun2(base_level,base_product_info)
    # product_level_df=model.fun3(product_level_df)
    product_level_df.drop_duplicates(subset=['template_brand','level_id'], keep='first', inplace=True)
    return product_level_df

def process_template_level_rate_final():
    product_level_df1=process_product_level_rate(SETTLE_DATA)
    product_level_df2=process_product_level_rate(SETTLE_DATA_2)
    product_level_df3=process_product_level_rate(SETTLE_DATA_3)
    #测试
    # product_level_df1=product_level_df3
    # product_level_df2=product_level_df3

    tmp1=product_level_df1[['template_brand','level_id','sku_rate','rate_f', 'sale_sum']]
    tmp1.rename(columns={'rate_f':'rate_f1','sale_sum':'sale_sum1','sku_rate':'sku_rate1'},inplace=True)
    tmp2=product_level_df2[['template_brand','level_id','sku_rate','rate_f', 'sale_sum']]
    tmp2.rename(columns={'rate_f':'rate_f2','sale_sum':'sale_sum2','sku_rate':'sku_rate2'},inplace=True)


    tmp3=product_level_df3[['template_brand','level_id','sku_rate','rate_f', 'sale_sum']]
    tmp3.rename(columns={'rate_f':'rate_f3','sale_sum':'sale_sum3','sku_rate':'sku_rate3'},inplace=True)

    tmp1=tmp1.merge(tmp2,left_on=['template_brand','level_id'],right_on=['template_brand','level_id'])
    tmp1=tmp1.merge(tmp3,left_on=['template_brand','level_id'],right_on=['template_brand','level_id'])


    tmp1.loc[tmp1.rate_f1>0 ,'w_f1']=0.5
    tmp1.loc[tmp1.rate_f2>0 ,'w_f2']=0.3
    tmp1.loc[tmp1.rate_f3>0 ,'w_f3']=0.2

    tmp1['rate_f1_w']=tmp1.w_f1*tmp1.rate_f1
    tmp1['rate_f2_w']=tmp1.w_f2*tmp1.rate_f2
    tmp1['rate_f3_w']=tmp1.w_f3*tmp1.rate_f3
    tmp1['mean_rate'] = tmp1[['rate_f1_w', 'rate_f2_w', 'rate_f3_w']].sum(axis=1)/tmp1[['w_f1', 'w_f2', 'w_f3']].sum(axis=1)
    tmp1['template_level_sale_cnt'] = tmp1[['sale_sum1', 'sale_sum2', 'sale_sum3']].sum(axis=1)
    tmp1['w_mean'] = tmp1[['w_f1', 'w_f2', 'w_f3']].sum(axis=1)
    tmp1['mean_rate_tmp']=tmp1['mean_rate']

    result_df=fun3(tmp1)
    result_df.to_csv('/data/sunpengwei/tmp/template_level_rate_tablet.csv', encoding='utf-8-sig')
    return result_df

#等级模板计算中测试用

#测试用
def main():
    result_df=process_template_level_rate_final()
    # df=predict_price_data(result_df)
    # df.to_csv('/data/sunpengwei/tmp/predict_price_level_rate.csv', encoding='utf-8-sig')
    print('1')

if __name__ == '__main__':
    main()